<?php

namespace App\Http\Controllers\ChatGroup\Web;

use App\Http\Controllers\BaseController;
use App\Http\Validate\Kms\Task\TaskValidate;
use App\Models\ChatGroup\ChatGroupFAQModel;
use App\Models\Kms\Task\TaskTemplateModel;
use App\Models\Shop\ShopModel;
use App\Service\ChatGroup\ChatGroupService;
use App\Service\Kms\Task\TaskService;
use App\Service\Shop\ShopService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class TaskController extends BaseController
{

    /**
     * 获取门店详情
     *
     * @param Request $request
     * @return JsonResponse
     */
    public function getShopInfo(Request $request): JsonResponse
    {
        $shopId        = (int)$request->get('shopId');
        $shopInfo      = ShopModel::getDataById($shopId);
        $councilorInfo = $shopInfo->councilorRel;

        return $this->success([
            'shopName'      => $shopInfo->name,
            'shopCode'      => $shopInfo->shopCode,
            'province'      => $shopInfo->province,
            'city'          => $shopInfo->city,
            'district'      => $shopInfo->district,
            'councilorInfo' => [
                'userId'   => $councilorInfo->rmsUserId ?? 0,
                'username' => empty($councilorInfo->rmsUserId) ? "" : "{$councilorInfo->nickname}（{$councilorInfo->name}）"
            ]
        ]);
    }

    /**
     * 日常任务添加
     *
     * @return JsonResponse
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws \Exception
     */
    public function addTask(): JsonResponse
    {
        TaskService::add(TaskValidate::addValidate(), \request()->user()->id, TaskTemplateModel::TEMPLATE_TYPE_1);
        return $this->success();
    }
}
